package com.hu.jie.mywallpager.fragment;

import android.graphics.Bitmap;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * Created by jie on 2016/7/5.
 */
public class MyImagcache implements ImageLoader.ImageCache {
    private LruCache<String,Bitmap> mCache;

    public MyImagcache(){
        long maxMemory = Runtime.getRuntime().maxMemory() / 8;
        mCache = new LruCache<String, Bitmap>((int) maxMemory){
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getByteCount();
            }
        };
    }
    @Override
    public Bitmap getBitmap(String url) {
        return mCache.get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        if (getBitmap(url)==null)
        mCache.put(url,bitmap);
    }
}
